<template>
  <div class="game-select min-h-screen flex items-center justify-center p-4">
    <!-- 背景动画 -->
    <div class="background-animation"></div>
    
    <!-- 添加全屏按钮 -->
    <button 
      @click="toggleFullscreen" 
      class="absolute top-4 right-4 text-white/80 hover:text-white transition-colors duration-300 flex items-center gap-2 bg-white/10 px-4 py-2 rounded-lg backdrop-blur-sm"
    >
      <span class="text-lg">{{ isFullscreen ? '退出全屏' : '全屏显示' }}</span>
      <span class="text-xl">{{ isFullscreen ? '⤓' : '⤢' }}</span>
    </button>

    <div class="max-w-4xl w-full bg-white/10 backdrop-blur-lg rounded-2xl p-8 shadow-2xl border border-white/20">
      <h1 class="text-5xl font-bold text-center text-white mb-12 shadow-text animate-title">
        趣味游戏集
        <div class="text-lg font-normal mt-2 text-white/80">选择你喜欢的游戏开始玩吧！</div>
      </h1>
      
      <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-5xl mx-auto">
        <!-- 记忆配对游戏卡片 -->
        <div class="game-card group" @click="$router.push('/memory-game')">
          <div class="card-content">
            <div class="card-icon-bg memory-bg">
              <div class="card-icons">🎴</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-purple-300">记忆配对游戏</h2>
            <p class="text-white/80">考验记忆力的趣味配对游戏，找出所有配对的卡片！</p>
          </div>
        </div>

        <!-- 寻宝传奇卡片 -->
        <div class="game-card group" @click="$router.push('/treasure-hunt')">
          <div class="card-content">
            <div class="card-icon-bg treasure-bg">
              <div class="card-icons">💎</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-yellow-300">寻宝传奇</h2>
            <p class="text-white/80">寻找隐藏的宝藏，考验你的运气和直觉！</p>
          </div>
        </div>

        <!-- 草原射箭卡片 -->
        <div class="game-card group" @click="$router.push('/prairie-archery')">
          <div class="card-content">
            <div class="card-icon-bg archery-bg">
              <div class="card-icons">🎯</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-green-300">草原射箭</h2>
            <p class="text-white/80">测试你的反应能力，击中移动的目标！</p>
          </div>
        </div>

        <!-- 贪吃蛇游戏卡片 -->
        <div class="game-card group" @click="$router.push('/snake-game')">
          <div class="card-content">
            <div class="card-icon-bg snake-bg">
              <div class="card-icons">🐍</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-emerald-300">贪吃蛇</h2>
            <p class="text-white/80">经典贪吃蛇游戏，考验你的反应和策略！</p>
          </div>
        </div>

        <!-- 赛车游戏卡片 -->
        <div class="game-card group" @click="$router.push('/racing-game')">
          <div class="card-content">
            <div class="card-icon-bg racing-bg">
              <div class="card-icons">🏎️</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-red-300">极速赛车</h2>
            <p class="text-white/80">体验速度与激情，在赛道上一决高下！</p>
          </div>
        </div>

        <!-- 唐诗益智游戏卡片 -->
        <div class="game-card group" @click="$router.push('/tang-poetry-game')">
          <div class="card-content">
            <div class="card-icon-bg poetry-bg">
              <div class="card-icons">📚</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-blue-300">唐诗益智游戏</h2>
            <p class="text-white/80">测试你的唐诗知识，享受诗词之美！</p>
          </div>
        </div>

        <!-- 垃圾分类游戏卡片 -->
        <div class="game-card group" @click="$router.push('/TrashSorting')">
          <div class="card-content">
            <div class="card-icon-bg trash-bg">
              <div class="card-icons">🗑️</div>
            </div>
            <h2 class="text-2xl font-bold text-white mb-3 group-hover:text-green-300">垃圾分类</h2>
            <p class="text-white/80">学习垃圾分类知识，保护环境从我做起！</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';

// 添加全屏相关的状态和方法
const isFullscreen = ref(false);

// 检查是否处于全屏状态
const checkFullscreen = () => {
  isFullscreen.value = !!(
    document.fullscreenElement ||
    document.webkitFullscreenElement ||
    document.mozFullScreenElement ||
    document.msFullscreenElement
  );
};

// 切换全屏状态
const toggleFullscreen = async () => {
  if (!isFullscreen.value) {
    try {
      if (document.documentElement.requestFullscreen) {
        await document.documentElement.requestFullscreen();
      } else if (document.documentElement.webkitRequestFullscreen) {
        await document.documentElement.webkitRequestFullscreen();
      } else if (document.documentElement.mozRequestFullScreen) {
        await document.documentElement.mozRequestFullScreen();
      } else if (document.documentElement.msRequestFullscreen) {
        await document.documentElement.msRequestFullscreen();
      }
    } catch (error) {
      console.error('Failed to enter fullscreen:', error);
    }
  } else {
    try {
      if (document.exitFullscreen) {
        await document.exitFullscreen();
      } else if (document.webkitExitFullscreen) {
        await document.webkitExitFullscreen();
      } else if (document.mozCancelFullScreen) {
        await document.mozCancelFullScreen();
      } else if (document.msExitFullscreen) {
        await document.msExitFullscreen();
      }
    } catch (error) {
      console.error('Failed to exit fullscreen:', error);
    }
  }
};

// 监听全屏变化事件
onMounted(() => {
  document.addEventListener('fullscreenchange', checkFullscreen);
  document.addEventListener('webkitfullscreenchange', checkFullscreen);
  document.addEventListener('mozfullscreenchange', checkFullscreen);
  document.addEventListener('MSFullscreenChange', checkFullscreen);
});

// 清理事件监听
onUnmounted(() => {
  document.removeEventListener('fullscreenchange', checkFullscreen);
  document.removeEventListener('webkitfullscreenchange', checkFullscreen);
  document.removeEventListener('mozfullscreenchange', checkFullscreen);
  document.removeEventListener('MSFullscreenChange', checkFullscreen);
});
</script>

<style scoped>
.game-select {
  background: linear-gradient(135deg, #1a1a1a 0%, #2d3436 100%);
  position: relative;
  overflow: hidden;
}

.background-animation {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 20%, rgba(62, 84, 172, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(148, 62, 172, 0.2) 0%, transparent 50%);
  animation: backgroundPulse 10s ease-in-out infinite alternate;
}

@keyframes backgroundPulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.2); opacity: 0.8; }
}

.game-card {
  @apply relative overflow-hidden rounded-xl transition-all duration-300 cursor-pointer;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.card-content {
  @apply p-6 relative z-10;
  background: linear-gradient(
    to bottom right,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.05)
  );
}

.game-card:hover {
  @apply transform scale-105 shadow-2xl;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.card-icon-bg {
  @apply w-16 h-16 rounded-full flex items-center justify-center mb-4 transition-transform duration-300;
}

.game-card:hover .card-icon-bg {
  transform: scale(1.1) rotate(5deg);
}

.memory-bg { background: linear-gradient(135deg, #9b59b6, #6c5ce7); }
.treasure-bg { background: linear-gradient(135deg, #f1c40f, #e67e22); }
.archery-bg { background: linear-gradient(135deg, #2ecc71, #27ae60); }
.snake-bg { background: linear-gradient(135deg, #00b894, #00cec9); }
.racing-bg { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.poetry-bg { background: linear-gradient(135deg, #3498db, #2980b9); }
.trash-bg { background: linear-gradient(135deg, #10B981, #059669); }

.card-icons {
  @apply text-3xl transition-transform duration-300;
}

.shadow-text {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.animate-title {
  animation: titleAnimation 1s ease-out;
}

@keyframes titleAnimation {
  0% {
    opacity: 0;
    transform: translateY(-50px);
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 添加卡片出现动画 */
.game-card {
  animation: cardAppear 0.5s ease-out backwards;
}

.game-card:nth-child(1) { animation-delay: 0.1s; }
.game-card:nth-child(2) { animation-delay: 0.2s; }
.game-card:nth-child(3) { animation-delay: 0.3s; }
.game-card:nth-child(4) { animation-delay: 0.4s; }
.game-card:nth-child(5) { animation-delay: 0.5s; }
.game-card:nth-child(6) { animation-delay: 0.6s; }

@keyframes cardAppear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 添加全屏按钮的悬浮效果 */
button:hover .text-xl {
  transform: scale(1.2);
}

button .text-xl {
  transition: transform 0.3s ease;
}
</style> 